package com.lms.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lms.entity.Dinebuildbaseinfo;
import com.lms.entity.Dormbuildbaseinfo;
import com.lms.mapper.DinebuildbaseinfoMapper;
import com.lms.service.DinebuildbaseinfoService;
import com.lms.vo.DataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 餐饮建筑基础信息业务逻辑层接口实现类
 * @author: L-B-S
 * @Date: 2021/3/17 19:45
 * @modified_By:
 * @Version: 0.0$
 */
@Service
public class DinebuildbaseinfoServiceImpl implements DinebuildbaseinfoService {

    @Autowired
    private DinebuildbaseinfoMapper dinebuildbaseinfoMapper;

    @Override
    public DataVo<Dinebuildbaseinfo> getList(Integer page, Integer limit) {
        DataVo<Dinebuildbaseinfo> dataVo = new DataVo<>();

        IPage<Dinebuildbaseinfo> dinebuildbaseinfoPage = new Page<>(page, limit);
        dataVo.setCode(0);
        dataVo.setMsg("");
        IPage<Dinebuildbaseinfo> result = dinebuildbaseinfoMapper.selectPage(dinebuildbaseinfoPage, null);
        dataVo.setData(result.getRecords());
        dataVo.setCount(result.getTotal());

        return dataVo;
    }

    @Override
    public DataVo<Dinebuildbaseinfo> add(Dinebuildbaseinfo dinebuildbaseinfo) {
        DataVo<Dinebuildbaseinfo> dataVo = new DataVo<>();
        Dinebuildbaseinfo dbbi = dinebuildbaseinfoMapper.selectByDineBuild(dinebuildbaseinfo.getDineBuild());
        if (dbbi != null) {
            dataVo.setCode(1);
            dataVo.setMsg("此编号的宿舍楼宇已存在，请修改后再试");
        } else {
            dinebuildbaseinfoMapper.insert(dinebuildbaseinfo);
            dataVo.setCode(0);
            dataVo.setMsg("新增数据成功，正在刷新数据，请稍等...");
        }
        return dataVo;
    }
}